export function Rule(obj) {
    if (obj < 10) return "0" + obj
    else return obj
}

// 根据日期查询星期几函数
export function queryday(data) {
    // let weekArrayList = ['周天', '周一', '周二', '周三', '周四', '周五', '周六']
    let weekArrayList = [1, 2, 3, 4, 5, 6, 7]

    let index = new Date(data).getDay()

    let week = weekArrayList[index]

    return week
}

// 获取本周的开始日期和结束日期
export function queryweek(date) {

    // 获取今日的年月日
    const year = date.getFullYear()
    const month = date.getMonth()
    const day = date.getDate()
    const week = date.getDay()

    // 计算本周开始日期
    let StartTime = new Date(year, month, day - week + 1).getTime() - 86400000
    let WeekStartDate = StartTime;

    let target = []
    for (let i = 0; i < 7; i++) {
        let ans = (Number(Rule(new Date(StartTime).getMonth())) + 1) + '/' + Rule(new Date(StartTime).getDate())
        target.push(ans)
        StartTime = StartTime + 86400000
    }
    return {
        target,
        WeekStartDate
    }
}

// 获得年-月-日格式字符串
export function getYMD(myDate) {
    const TimeData =
        myDate.getFullYear() +
        "/" +
        Rule(myDate.getMonth() + 1) +
        "/" +
        Rule(myDate.getDate()); //表示当前日期

    return {
        TimeData
    }
}

// 时分秒（00:00:00）转为 时间戳
export function TimeTosec(time) {
    let s = '';

    let hour = time.split(':')[0];
    let min = time.split(':')[1];
    let sec = time.split(':')[2];

    s = Number(hour * 3600) + Number(min * 60) + Number(sec);

    return s;
};